//
//  RegisterViewController.m
//  CivilianTravel
//
//  Created by xalo on 16/7/28.
//  Copyright © 2016年 许仕杰. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *name;

@property (weak, nonatomic) IBOutlet UITextField *passWord;
@property(nonatomic,assign)BOOL *ispp;

@property (weak, nonatomic) IBOutlet UIButton *buuu;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


//注册
- (IBAction)registerAction:(id)sender {
    dispatch_async(dispatch_get_main_queue(), ^{
        
    

        EMError *error = [[EMClient sharedClient] registerWithUsername:self.name.text  password:self.passWord.text];
        
        // 正则表达式判断是不是电话号码
        
        //    电信号段:133/153/180/181/189/177
        //    联通号段:130/131/132/155/156/185/186/145/176
        //    移动号段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178
        //    虚拟运营商:170

        NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[06-8])\\d{8}$";
        
        NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
        
        BOOL ispp=  [regextestmobile evaluateWithObject:self.name.text];
        
        if (ispp) {
            
        if (error==nil) {
            
            NSLog(@"注册成功");
            if (self.block) {
                self.block(self.name.text ,self.passWord.text);
            }
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"注册成功" preferredStyle:UIAlertControllerStyleAlert];
            [self presentViewController:alert animated:YES completion:^{
                [self performSelector:@selector(removeAlertView:) withObject:alert afterDelay:0.8];
                [self dismissViewControllerAnimated:YES completion:nil];
            }];
        }
            
        }else{
            UIAlertView *aler = [[UIAlertView alloc]initWithTitle:@"电话号码错误" message:@"请重新输入" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
   
            [aler show];

       
        }
        
    });
    
}



- (IBAction)retun:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}


-(void)removeAlertView:(UIAlertController *)snder{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
